fn main() {
    let s = String::from("Hello Slice!");
    println!("{}", s);

    let word = first_word(&s[0..3]);
    // s.clear();
    println!("{}", word);

    let word = first_word(&s);
    // s.clear();
    println!("{}", word);

    let a = [1, 2, 3, 4, 5];
    let b = &a[3..5];
    assert_eq!(b, &[4, 5]);
}

fn first_word(s: &str) -> &str {
    let bytes = s.as_bytes();
    // println!("iter: {}", bytes.iter());
    // println!("enum: {}", bytes.iter().enumerate());

    for (i, &item) in bytes.iter().enumerate() {
        if item == b' ' {
            return &s[0..i];
        }
    }

    &s[..]
}

// fn second_word(s: &String) -> &str {

// }